//
//  CAHBJLViewController.m
//  LNH
//
//  Created by twentylx on 2018/1/26.
//  Copyright © 2018年 twentylx. All rights reserved.
//

#import "CAHBJLViewController.h"
#import "CAHBJLHeaderView.h"
#import "CAHBJLTableViewCell.h"

@interface CAHBJLViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) CAHBJLHeaderView *headerView;

@property (nonatomic, strong) UITableView *hbTableView;
@property (nonatomic, strong) NSMutableArray *hbArray;

@end

static NSString *cellIdentifier = @"JLCell";

@implementation CAHBJLViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)lm_initialDefaultsForController {
    NSArray *array = @[
                       @{@"image" : @"sale1"},
                       @{@"image" : @"sale2"},
                       @{@"image" : @"sale3"},
                       @{@"image" : @"sale4"},
                       @{@"image" : @"sale5"},
                       ];
    _hbArray = [NSMutableArray arrayWithArray:array];
}

/// 绑定 vm
- (void)lm_bindViewModelForController {
    
}

/// 创建视图
- (void)lm_createViewForController {
    [self.view setNeedsUpdateConstraints];
    
    [self.view addSubview:self.headerView];
    [self.view addSubview:self.hbTableView];
}

/// 配置导航栏
- (void)lm_configNavigationForController {
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationItem.title = @"红包奖励列表";
}

#pragma mark layout
- (void)updateViewConstraints {
    [super updateViewConstraints];
    
    [_headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.view);
        make.top.equalTo(self.view);
        make.height.mas_equalTo(60);
    }];
    
    [_hbTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.view);
        make.top.equalTo(self.headerView.mas_bottom);
        make.bottom.equalTo(self.view);
    }];
}

#pragma mark get & set
- (CAHBJLHeaderView *)headerView {
    if (!_headerView) {
        _headerView = [CAHBJLHeaderView new];
    }
    return _headerView;
}

- (UITableView *)hbTableView {
    if (!_hbTableView) {
        _hbTableView = [UITableView new];
        _hbTableView.dataSource = self;
        _hbTableView.delegate = self;
        _hbTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_hbTableView registerClass:[CAHBJLTableViewCell class] forCellReuseIdentifier:cellIdentifier];
    }
    return _hbTableView;
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.hbArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CAHBJLTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    NSDictionary *dict = _hbArray[indexPath.row];
    //    cell.titleLabel.text = @"ceshi";
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //
    return cell;
}

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}

@end
